package com.charm.watercress.adapter

import android.widget.ImageView
import android.widget.RatingBar
import android.widget.TextView
import com.chad.library.adapter.base.BaseViewHolder
import com.charm.codes.imageLoad.XGlide
import com.charm.frameworkarou.recycleadapter.QuickRecyAdapter
import com.charm.watercress.R
import com.charm.watercress.entity.BookEntity
import com.charm.watercress.entity.FilmEntity

/**
 * Created by tools on 2018/1/11.
 */
class BookAdapter(list: List<BookEntity>?) : QuickRecyAdapter<BookEntity>(list) {
    override fun convert(helper: BaseViewHolder?, item: BookEntity?) {
        helper!!.getView<TextView>(R.id.title).text = item!!.title
        var image = helper!!.getView<ImageView>(R.id.image)
        if (item.coverUrl != null) {
            XGlide.getInstance().with(mContext)
                    .load(item.coverUrl)
                    .placeholder(R.drawable.bg_block)
                    .error(R.drawable.bg_block)
                    .into(image)
                    .displayImage()
        }
        helper!!.getView<RatingBar>(R.id.rating).rating = item.rating.toFloat()
    }

    override fun getLayoutResId(): Int {
        return R.layout.item_film
    }

}